function  masterfile(file,seconds, useGPU)

file = 'test.wav';
if nargin < 2, seconds = 0; end
if seconds == 0
    [y, Fs] = wavread(file);      % data= y, sampling freq = Fs
else
    [y, Fs] = wavread(file,[1 44100*seconds]);   % for a certain range
end



% Common Variables
player = audioplayer(y,Fs);
y = y(:,1)*10;
if (useGPU)
    y = gsingle(y);     
end
lenY = length(y);
lengthSong = lenY/Fs;
timeToJump = 2.2;
timeSkip = 350/44100;
goodTill = 0;
val = [];


g2max=1;
g3max=13;
g4max = 1;

[xs,ys,zs] = sphere(10);

sphTrans = [0,0,0;10,-10,10;10,-10,-10;0,0,-15;-10,10,-10;-10,10,10];
if (useGPU)
    xs = gsingle(xs);
    ys = gsingle(ys);
    zs = gsingle(zs);
    sphTrans = [0,0,0; -10,-10,0;  -10,0,0; 0,-15,0;0,0,-10; 0,-10,-10];
    
end


%%%%%%
lastTimeFFT = 0;
time = 0;

play(player);
myt = tic;
while time<lengthSong
    tic
    time = toc(myt);
    
    % For the FFT Analysis, which happens only once every 2.2 seconds
    if (or((goodTill <= time),(goodTill-time) < .2)) % Testing if we're past the last analyzed point, or close to it
        if (lengthSong - time > timeToJump)
            % There are more than 2.2 seconds left in the song
            startFrameFFT = ceil(time*44100);
            endFrameFFT = ceil((time+timeToJump)*44100);
            sigBandsFFT = rhythm(y(startFrameFFT:endFrameFFT));
            goodTill = time + timeToJump;
            lastTimeFFT = time;
        else
            % If less then 2.2 seconds left, grab the last 2.2 seconds
            sigBandsFFT = rhythm(y((ceil((lengthSong - timeToJump)*44100):ceil((lengthSong)*44100))));
            goodTill = lenY;
            lastTimeFFT = time;
            
        end
        
        % For the second plot, normalized individual bands
        if (useGPU)
            gsubplot(2,2,2);
            upperlimit = gones(1, 1)*g2max;
            plot(upperlimit); % Plotting the upper limit
            ghold_on;
        else
            subplot(2,2,2);
            upperlimit = ones(1, 1)*g2max;
            plot(upperlimit);
            hold on;
        end
        plot(upperlimit*0); % Plotting the lower limit
        
        for i=1:6
            c =abs(sigBandsFFT(:,i));
            c = c/max(c);
            plot(c);
            
        end
        
        saveForLater = abs(sigBandsFFT);
        
        if (useGPU)
            ghold_off
        else
            hold off;
        end
        
    end
    
    % waveformRange is for the wave form ranges, which is updated on every loop run
    % If at the beginning of song, just grabbing the first interval
    if (time < timeSkip)
        time = timeSkip+.001;
    end
    waveformRange = [ceil((time-timeSkip)*44100) ceil((time+timeSkip)*44100)];
    
    % Making sure to not have a limit beyond song length
    if (waveformRange(2) >= lenY)
        waveformRange(2)= lenY;
    end
    
    waveformRange = waveformRange(1):waveformRange(end);
    % If the input range is empty, we're past the end of the song
    if isempty(waveformRange)
        break;
    end
    % First plot, waveform
    if (useGPU)
        gsubplot(2,2,1);
    else
        subplot(2,2,1);
    end
    plot(y(waveformRange)/max(abs(y(waveformRange)))) %plotting the data with limits -1 to 1
    
    
    %%% For the third plot, six spheres
    if (useGPU)
        gsubplot(2,2,3);
    else
        subplot(2,2,3);
    end
    
    deltatime = time-lastTimeFFT;
    deltaFrame = ceil(deltatime*44100);
    if deltaFrame == 0
        deltaFrame = 1;
    end
    
    maxvalues = max(saveForLater);
    tsaveForLater = saveForLater;
    %Normalizing with respect to the max values
    if (useGPU)
        gfor i=1:6
        tsaveForLater(:,i) =  2*tsaveForLater(:,i)/maxvalues(i);
        gend
    else
        for i=1:6
            tsaveForLater(:,i) =  2*tsaveForLater(:,i)/maxvalues(i);
        end
    end
    if (useGPU)
        X = gsingle([]); %middle
        Y = gsingle([]);
        Z = gsingle([]);
    else
        X = []; %middle
        Y = [];
        Z = [];
    end

    for i = 1:6
        X = [X; xs(:)*tsaveForLater(deltaFrame,i)-sphTrans(i,1)];
        Y = [Y; ys(:)*tsaveForLater(deltaFrame,i)-sphTrans(i,2)];
        Z = [Z; zs(:)*tsaveForLater(deltaFrame,i)-sphTrans(i,3)];
    end
    
    
    X = [X;-1*g3max;1*g3max]; %limits
    Y = [Y;-1*g3max;1*g3max];
    Z = [Z;-1*g3max;1*g3max];
    scatter3(X(:),Y(:),Z(:))
    
    % Fourth plot, a single way to see the beat
    if (useGPU)
        gsubplot(2,2,4)
        sumsaveForLater = gzeros(1,6);
        
    else
        subplot(2,2,4)
        sumsaveForLater = zeros(1,6);
        
    end
    
    for i=1:6
        
        sumsaveForLater(i) =sumsaveForLater(i)+ tsaveForLater(deltaFrame,i) ;
    end
    
    [a b] = max(maxvalues);
    
    sumsaveForLater = sumsaveForLater - .5*min(sumsaveForLater);
    sumsaveForLater = sumsaveForLater/max(sumsaveForLater);
    
    realsum = sum(sumsaveForLater)/6;
    % sumsaveForLater = gones(1,6)*realsum
    %sumsaveForLater = tsaveForLater(deltaFrame,b);
    
    X = [xs(:)*tsaveForLater(deltaFrame,1)]; %middle
    Y = [ys(:)*tsaveForLater(deltaFrame,1)];
    Z = [zs(:)*tsaveForLater(deltaFrame,1)];
    
    
    
    X = [X;-1*g4max;1*g4max]; %limits
    Y = [Y;-1*g4max;1*g4max];
    Z = [Z;-1*g4max;1*g4max];
    scatter3(X(:),Y(:),Z(:))
    
    
    pause(.01);
    
    toc
    val = [val toc];
    mean(val);
end
